package com.ly.base.annotation.example;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Classname FileOperator
 * @Description TODO
 * @Date 2020/4/12 10:28
 * @Author 冷心影翼
 */
public class Main {

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
//        Class clazz = Class.forName("main.java.annotation.example.Test");
        Class<Test> clazz = Test.class;
        Object o = clazz.newInstance();
        int allM = 0;
        int successM = 0;
        int errorM = 0;

        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method m : declaredMethods) {
            TestFunction annotation = m.getAnnotation(TestFunction.class);
            allM++;
            if(annotation != null)
            {
                try {
                    m.invoke(o);
                    successM++;
                } catch (InvocationTargetException e) {
                    errorM++;
                }
            }

        }
        System.out.println( "all "+allM +"success "+successM +"error "+errorM);
    }
}
